package com.jisf.driver.controller;

import com.jisf.driver.entity.vo.*;
import com.jisf.driver.response.Result;
import com.jisf.driver.response.ResultCode;
import com.jisf.driver.service.ICoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jisf
 * @since 2022-05-06
 */
@RestController
@RequestMapping("/driver/coach")
public class CoachController {

    @Autowired
    private ICoachService iCoachService;

    @PostMapping("coach/list")
    @PreAuthorize("hasAnyAuthority('coach:coach:list')")
    public Result<?> getCoachList(@RequestBody CoachListVo coachListVo){
        CoachListResponseVo coachList = iCoachService.getCoachList(coachListVo);
        return Result.ok(coachList);
    }

    @GetMapping("getAllCoach")
    @PreAuthorize("hasAnyAuthority('coach:getAllCoach')")
    public Result<?> getAllCoach(){
        List<ExamineCoachResponseVo> allCoach = iCoachService.getAllCoach();
        return Result.ok(allCoach);
    }

    @GetMapping("getExamineCoach")
    @PreAuthorize("hasAnyAuthority('coach:getExamineCoach')")
    public Result<?> getExamineCoach(@RequestParam Integer id){
        List<ExamineCoachResponseVo> courseCoach = iCoachService.getExamineCoach(id);
        return Result.ok(courseCoach);
    }

    @GetMapping("getMessage")
    @PreAuthorize("hasAnyAuthority('coach:getMessage')")
    public Result<?> getMessage(){
        CoachMessageVo message = iCoachService.getMessage();
        return Result.ok(message);
    }

    @PostMapping("completeMessage")
    @PreAuthorize("hasAnyAuthority('coach:completeMessage')")
    public Result<?> completeMessage(@RequestBody CoachMessageVo coachMessageVo){
        ResultCode resultCode = iCoachService.completeMessage(coachMessageVo);
        return Result.ok(resultCode);
    }

    @PostMapping("allCoach")
    @PreAuthorize("hasAnyAuthority('coach:allCoach')")
    public Result<?> allCoach(@RequestBody UserListRequestVo userListRequestVo){
        CoachMessageResponseVo message = iCoachService.allCoach(userListRequestVo);
        return Result.ok(message);
    }

    @PostMapping("update/coach")
    @PreAuthorize("hasAnyAuthority('coach:update:coach')")
    public Result<?> updateCoach(@RequestBody CoachMessageVo coachMessageVo){
        ResultCode resultCode = iCoachService.updateCoach(coachMessageVo);
        return Result.ok(resultCode);
    }

}
